package leetcode;

import java.util.Arrays;

/**
 * 贪心算法：根据身高重建队列
 */
public class Solution33 {
    class Solution {
        public int[][] reconstructQueue(int[][] people) {
            //对people进行排序
            Arrays.sort(people, (a , b) ->{
                if(a[0] == b[0]) return a[1] - b[1];
                return b[0] - a[0];
            });

            LinkedList<int[]> que = new LinkedList<>();
            for(int[] p : people){
                que.add(p[1],p);
            }

            return que.toArray(new int[people.length][]);
        }
    }
}
